package co.fitstart.admin.web.controller.user.agent;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.persistence.support.Order;
import com.demo2do.core.support.Page;
import com.demo2do.core.web.utils.WebUtils;

import co.fitstart.admin.service.DataService;
import co.fitstart.admin.web.interceptor.MenuSetting;
import co.fitstart.entity.user.agent.OfflineAgent;

/**
 * 
 * @author dan
 *
 */
@Controller
@RequestMapping("/offline-agents")
@MenuSetting("menu-user")
public class OfflineAgentController {
    
    @Autowired
    @Qualifier("dataService")
    private DataService<OfflineAgent> offlineAgentService;
    
    /**
     * 
     * @param page
     * @param request
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-offline-agent")
    public ModelAndView list(Page page, HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("user/offline-agent/agent-list");
        
        List<OfflineAgent> offlineAgents = offlineAgentService.listByPage(OfflineAgent.class, new Order("createTime", "DESC"), page);
        modelAndView.addObject("offlineAgents", offlineAgents);
        
        modelAndView.addObject("page", page);
        
        modelAndView.addObject("refer", "list");
        modelAndView.addObject("queryString", WebUtils.extractQueryString(request, "page"));
        return modelAndView;
    }

}
